#include <iostream>
#include "graphtypes.h"
#include "GraphFlowMatrix.h"
#include "GraphFlowList.h"
#include <vector>
#include "unistd.h"
#include "time.h"
#include "math.h"

using namespace std;

int main(int argc, char * argv[], char * envp[])
{
  long int t;
  if (argc == 2)
  {
    t = atoi(argv[1]);
  }
  else
  {
    t = time(NULL);
  }
  //t=1416919469;
  cerr<<"Graine : "<<t<<endl;
  srand(t);

  struct timespec t1, t2;
  float ex_t1, ex_t2, ex_t3, ex_t4;
  
  

  //std::cout.setf( std::ios::fixed, std:: ios::floatfield );

  GraphFlow * graphEcart1, * graphEcart2, * graphEcart3, * graphEcart4;  
  
  summit_t i = 2;
  edges_t m;
  flow_t c1=0, c2=1;
  
  while (c1<c2) {
    ex_t1 = ex_t2 = ex_t3 = ex_t4 = 0;
    c1=c2;
    c2=pow(1.1,i)+1;
    cerr<<"Capacité max pour C. exp. : "<<c2<<endl;
    m = max(i*(i-1)/(10/3),i-1);

    for (int j=1; j<=700; j++)
    {
      graphEcart1 = new GraphFlowMatrix(i,m);
      graphEcart1->fill(1,100);
      graphEcart2 = new GraphFlowMatrix(i,m);
      graphEcart2->fill(1,i);
      graphEcart3 = new GraphFlowMatrix(i,m);
      graphEcart3->fill(1,c2);
      graphEcart4 = new GraphFlowMatrix(*graphEcart3);
      
      clock_gettime(CLOCK_REALTIME,&t1);
      graphEcart1->doCapacityScaling();
      clock_gettime(CLOCK_REALTIME,&t2);
      t2.tv_sec-=t1.tv_sec;
      t2.tv_nsec-=t1.tv_nsec;
      ex_t1+=t2.tv_sec*1000+(t2.tv_nsec/1.0e6);
      //cout<<"  -----  -----  -----  -----  -----\n"
      
      clock_gettime(CLOCK_REALTIME,&t1);
      graphEcart2->doCapacityScaling();
      clock_gettime(CLOCK_REALTIME,&t2);
      t2.tv_sec-=t1.tv_sec;
      t2.tv_nsec-=t1.tv_nsec;
      ex_t2+=t2.tv_sec*1000+(t2.tv_nsec/1.0e6);
      //cout<<"  -----  -----  -----  -----  -----\n";
      
      clock_gettime(CLOCK_REALTIME,&t1);
      graphEcart3->doCapacityScaling();
      clock_gettime(CLOCK_REALTIME,&t2);
      t2.tv_sec-=t1.tv_sec;
      t2.tv_nsec-=t1.tv_nsec;
      ex_t3+=t2.tv_sec*1000+(t2.tv_nsec/1.0e6);
      //cout<<"  -----  -----  -----  -----  -----\n"
      
      clock_gettime(CLOCK_REALTIME,&t1);
      graphEcart4->doFordFulkerson();
      clock_gettime(CLOCK_REALTIME,&t2);
      t2.tv_sec-=t1.tv_sec;
      t2.tv_nsec-=t1.tv_nsec;
      ex_t4+=t2.tv_sec*1000+(t2.tv_nsec/1.0e6);
      //cout<<"  -----  -----  -----  -----  -----\n"
      
      delete graphEcart1;
      delete graphEcart2;
      delete graphEcart3;
      delete graphEcart4;
    }
    cout<<i<<"\t\t"<<ex_t1<<"\t\t"<<ex_t2<<"\t\t"<<ex_t3<<"\t\t"<<ex_t4<<endl;
    if (i%10)
      i-=(i%10);
    i+=10;
    }
  return EXIT_SUCCESS;
}
